﻿@model PetaPoco.Page<Shop.Order.Models.AnyOrder>
@{
    //用户订单管理分布页
    Layout = null;
}
@if (Model.Items.Count != 0)
{
    <table class="table table-bordered table-striped table-hover">
        <tr>
            <td>序号</td>
            <td>订单号</td>
            <td>购买数量</td>
            <td>总价格</td>
            <td>是否支付</td>
            <td>下单时间</td>
            <td>管理</td>
        </tr>

        @for (int i = 0; i < Model.Items.Count; i++)
        {
            <tr>
                <td>@(i + 1)</td>
                <td>@Model.Items[i].OrderNumber</td>
                <td>@Model.Items[i].Number</td>
                <td>@Model.Items[i].MoneyTotal 元</td>
                <td>@(Model.Items[i].IfPay == 0 ? "已支付" : "未支付")</td>
                <td>@Model.Items[i].CreateDate</td>
                <td>
                    <input type="button" class="btn btn-primary" value="管理此订单" onclick="OrderDetail('@Model.Items[i].OrderNumber')" />

                </td>
            </tr>
        }
    </table>
}
else
{
    <table class="table table-bordered table-striped table-hover">
        <tr>
            <td>序号</td>
            <td>订单号</td>
            <td>购买数量</td>
            <td>总价格</td>
            <td>是否支付</td>
            <td>下单时间</td>
            <td>管理</td>
        </tr>
        <tr>
            <td colspan="9">暂未有已完成订单</td>
        </tr>
    </table>
}
<div class="btn-toolbar" role="toolbar">
    @if (Model.TotalPages <= 1)
            {
        <div class="btn-group" role="group">
            <input type="button" class="btn btn-default disabled" value="首页" onclick="" />
            <input type="button" class="btn btn-default disabled" value="上一页" onclick="" />
            <input type="button" class="btn btn-default disabled" value="下一页" onclick="" />
            <input type="button" class="btn btn-default disabled" value="尾页" onclick="" />
        </div>
    }
    else if (Model.CurrentPage == 1 && Model.TotalPages != 1)
    {
        <div class="btn-group" role="group">
            <input type="button" class="btn btn-default disabled" value="首页" onclick="" />
            <input type="button" class="btn btn-default disabled" value="上一页" onclick="" />
            <input type="button" class="btn btn-default" value="下一页" onclick="NextPage()" />
            <input type="button" class="btn btn-default " value="尾页" onclick="Shadowe()" />
        </div>
    }
    else if (Model.CurrentPage > 1 && Model.CurrentPage < Model.TotalPages)
    {
        <div class="btn-group" role="group">
            <input type="button" class="btn btn-default" value="首页" onclick="HomePage()" />
            <input type="button" class="btn btn-default" value="上一页" onclick="PreviousPage()" />
            <input type="button" class="btn btn-default" value="下一页" onclick="NextPage()" />
            <input type="button" class="btn btn-default " value="尾页" onclick="Shadowe()" />
        </div>
    }
    else if (Model.CurrentPage == Model.TotalPages && Model.CurrentPage != 1)
    {
        <div class="btn-group" role="group">
            <input type="button" class="btn btn-default" value="首页" onclick="HomePage()" />
            <input type="button" class="btn btn-default" value="上一页" onclick="PreviousPage()" />
            <input type="button" class="btn btn-default disabled" value="下一页" onclick="" />
            <input type="button" class="btn btn-default disabled" value="尾页" onclick="" />
        </div>
    }
    <a class="btn btn-default">第@(Model.CurrentPage)页/共@(Model.TotalPages)页</a>

    <div class="col-lg-2">
        <div class="input-group">
            <input type="text" class="form-control" placeholder="输入页码" id="pagenum">
            <span class="input-group-btn">
                <button class="btn btn-default" type="button" id="GO" onclick="GoPage()">Go!</button>
            </span>
        </div>
    </div>
</div>
<script type="text/javascript">
     //首页
    function HomePage() {
        JumpPage("1");
    }
    //下一页
    function NextPage()
    {
        JumpPage("@(Model.CurrentPage+1)");
    }
    //上一页
    function PreviousPage()
    {
        JumpPage("@(Model.CurrentPage-1)");
    }
    //尾页
    function Shadowe()
    {
        JumpPage("@(Model.TotalPages)");
    }
    //跳转到页数
    function GoPage()
    {
        var page = $("#pagenum").val();
        if (page == "") {
            alert("请输入跳转的页数");
        }
        else if (page < 1) {
            alert("请输入正确的页数");
        }
        else if (page >@(Model.TotalPages))
        {
            alert("输入不能超过总页数");
        }
        else
        {
            JumpPage(page)
        }
    }
    function JumpPage(Page)
    {
        $.ajax({
            cache: false,
            type: 'post',
            url: '@Url.Action("_UserOrder", "Home")',
            data: { Page: Page },
            dataType: 'text',
            success: function (data) {
                $("#MyOrder").html(data);
            },
            error: function () {
                alert("Ajax调用出错请与管理员联系");
            }
        });
    }
    //订单详情
    function OrderDetail(OrderNumber)
    {
        $.ajax({
            cache: false,
            type: 'post',
            url: '@Url.Action("_UserOrderDetail", "Home")',
            data: { OrderNumber: OrderNumber },
            dataType: 'text',
            success: function (data) {
                  if (data == "User")
                {
                    alert("无效的用户状态，请重新登陆");
                    location.href = "@Url.Action("UsersLogin","User")";
                    return false;
                }
                $("#MyOrder").html(data);
            },
            error: function () {
                alert("Ajax调用出错请与管理员联系");
            }
        });
    }


     function DownloadBook(WID)
    {
        $.ajax({
            cache: false,
            type: 'post',
            url: '@Url.Action("_DownloadBook", "Home")',
            data: { WID: WID },
            dataType: 'text',
            success: function (data) {
                  @*if (data == "User")
                {
                    alert("无效的用户状态，请重新登陆");
                    location.href = "@Url.Action("UsersLogin","User")";
                    return false;
                }*@
                 //location.href = data;
               // $("#MyOrder").html(data);
            },
            error: function () {
                alert("Ajax调用出错请与管理员联系");
            }
        });
    }


    
</script>